package com.dhms.vostok1.data.abnormals

import com.squareup.moshi.Json


enum class FaultState(val value: String) {
    //观察中
    OBSERVING("observing"),

    //已处理
    HANDLED("handled"),

    //待处理
    OCCURRED("occurred"),

    //处理中
    ACCEPTED("accepted"),

    //已忽略
    CANCELLED("cancelled"),

    //已删除
    DELETED("deleted");

    val getName: String
        get() {
            return when (this) {
                OBSERVING -> "观察中"
                HANDLED -> "已完成"
                OCCURRED -> "待处理"
                ACCEPTED -> "处理中"
                CANCELLED -> "已忽略"
                DELETED -> "已删除"
            }
        }

    companion object {
        fun fromString(type: String) =
            FaultState.values().associateBy(FaultState::value)[type] ?: FaultState.OBSERVING

    }
}

enum class SpotSource(val value: String) {
    //点巡检
    SPOTPATROL("spot_patrol"),

    //交接班
    CONNECTCLASS("connect_class"),

    //定期点巡检
    CYCLEPATROL("cycle_patrol");

    companion object {
        fun fromString(type: String) =
            SpotSource.values().associateBy(SpotSource::value)[type]
                ?: SpotSource.SPOTPATROL
    }
}


/**
 *
 * @param id
 * @param name  异常项名称
 * @param handleDesc  异常处理描述
 * @param deviceId
 * @param deviceName
 * @param status  处理状态： observing, handled, occurred
 * @param source  异常上报的来源：？
 * @param reportTime
 * @param reportUserId
 * @param reportUserName
 * @param osss  异常照片/视频，附件
 * @param handleRecords  处理记录
 * @param desc  异常描述
 */

data class SpotAbnormalData(
    @Json(name = "id")
    val id: String,
    /*  异常项名称 */
    @Json(name = "name")
    val name: String,
    /*  异常处理描述 */
    @Json(name = "handle_desc")
    val handleDesc: String,
    @Json(name = "device_id")
    val deviceId: Long,
    @Json(name = "device_name")
    val deviceName: String,
    /*  处理状态： observing, handled, occurred */
    @Json(name = "status")
    val status: FaultState,

    /*  异常上报的来源： */
    @Json(name = "source")
    val source: SpotSource,
    @Json(name = "report_time")
    val reportTime: Long,
    @Json(name = "report_user_id")
    val reportUserId: Int,
    @Json(name = "report_user_name")
    val reportUserName: String,
    /*  异常照片/视频，附件 */
    //@Json(name = "osss")
    //val osss: List<AbnormalOssData>? = null,
    /*  处理记录 */
    @Json(name = "handle_records")
    val handleRecords: List<HandleRecordData>,
    /*  异常描述 */
    @Json(name = "desc")
    val desc: String? = null
)

